package com.jn.rxjava.http;

import android.text.TextUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Http Request Builder
 */
public class HttpRequest {
   public String url;
   public HttpCallback callBack;
   public Map<String, String> paramsMap;
   public Map<String, String> headersMap;

   private HttpRequest() {
      paramsMap = new HashMap<>();
      headersMap = new HashMap<>();
   }

   public static class Builder {
      HttpRequest httpRequest;

      public Builder() {
         httpRequest = new HttpRequest();
      }

      public Builder addParam(String name, String value) {
         httpRequest.paramsMap.put(name, value);
         return this;
      }

      public Builder addParamIfNotNull(String name, String value) {
         if (TextUtils.isEmpty(value)) {
            return this;
         }
         return addParam(name, value);
      }

      public Builder addParamsMap(Map<String, String> paramsMap) {
         httpRequest.paramsMap.putAll(paramsMap);
         return this;
      }

      public Builder addHeader(String name, String value) {
         httpRequest.headersMap.put(name, value);
         return this;
      }

      public Builder url(String url) {
         httpRequest.url = url;
         return this;
      }

      public Builder callBack(HttpCallback httpCallback) {
         httpRequest.callBack = httpCallback;
         return this;
      }

      public HttpRequest build() {
         return httpRequest;
      }
   }
}
